<template>
  <div class="home">
    <!-- 布局 -->
    <el-container>
      <!-- 头部 -->
      <el-header>
        <!-- layout左中右结构 -->
        <el-row :gutter="20">
          <el-col :span="4"
            ><img src="../assets/logo.png" class="logo" alt=""
          /></el-col>
          <el-col :span="16"><h2>后台管理系统</h2></el-col>
          <el-col :span="4"><span class="quit-login">退出登录</span></el-col>
        </el-row>
      </el-header>
      <!-- 大盒子里面放侧边栏和主体 -->
      <el-container>
        <!-- 侧边栏 -->
        <el-aside width="200px">
          <!-- 侧栏菜单 -->
          <el-menu
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            default-active="2"
            text-color="#fff"
            router
          >
            <!-- router开启路由模式,通过el-menu-item index来进行跳转,:index="item.path"可以选择颜色 -->
            <el-menu-item
              :index="item.path"
              v-for="item in list"
              :key="item.path"
            >
              <!-- <span>商品列表</span> -->
              <span>{{ item.meta.title }}</span>
            </el-menu-item>
          </el-menu></el-aside
        >
        <!-- 主体内容 -->
        <el-main>
          <!-- 设置路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useRouter } from "vue-router";
export default defineComponent({
  name: "HomeView",
  setup() {
    // 筛选meta值为true的子路由进行展示
    const router = useRouter(); // 接收
    console.log(router.getRoutes()); //获取所有路由
    const list = router.getRoutes().filter((v) => v.meta.isShow); //获取所有meta值为true的子路由
    console.log(list);
    return { list };
  },
  components: {},
});
</script>
<style lang="scss" scoped>
.el-header {
  height: 80px;
  background: #666;
  //logo
  .logo {
    height: 80px;
  }
  h2,
   //退出登录文字样式
  .quit-login {
    text-align: center;
    height: 80px;
    line-height: 80px;
    color: #fff;
  }
}
.el-aside {
  //侧边栏的高度为屏幕的100%减去头部的80px
  .el-menu {
    height: calc(100vh - 80px);
  }
}
</style>
